package com.chalk.common.util;

import java.io.File;
import java.util.List;

/**
 * @author xiaoqiang
 * @Description 视频第一帧处理工具
 * @date 2019/5/29 10:21
 */
public class FirstFrameUtil {
    //windows
    //private static  String FFMPEG_PATH = "D:/soft/ffmpeg/bin/ffmpeg.exe";
    //centos
    private static  String FFMPEG_PATH = "/usr/bin/ffmpeg";
    /**
     * FFmpeg
     * @param veidoPath
     * @return
     */
    public static boolean processImg(String veidoPath) {
        File file = new File(veidoPath);
        if (!file.exists()) {
            System.err.println("路径[" + veidoPath + "]对应的视频文件不存在!");
            return false;
        }
        List<String> commands = new java.util.ArrayList<String>();
        commands.add(FFMPEG_PATH);
        commands.add("-i");
        commands.add(veidoPath);
        commands.add("-y");
        commands.add("-f");
        commands.add("image2");
        commands.add("-ss");
        // 这个参数是设置截取视频多少秒时的画面
        commands.add("1");
        // commands.add("-t");
        // commands.add("0.001");
        commands.add("-s");
        commands.add("700x525");
        commands.add(veidoPath.substring(0, veidoPath.lastIndexOf("."))
                .replaceFirst("vedio", "file") + ".jpg");
        try {
            ProcessBuilder builder = new ProcessBuilder();
            builder.command(commands);
            builder.start();
            System.out.println("截取成功");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
